// pages/index/index.js
const app=getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        url:'',
        articleList:[],
        imageList:[],
        pageNum:1,
        pageSize:5,
    },

    onLoad(options) {
        //console.log(1111);
        this.setData({
            url:app.globalData.URL,
        })
        console.log(this.data.url);
        let that = this
        wx.request({
            url: that.data.url+'article/selectAll?pageNum='+that.data.pageNum+'&pageSize='+that.data.pageSize,
            success(resp){
              //console.log(resp.data.data.list)
              let slicedList = resp.data.data.list.slice(0, 5);
              let tabularCharts = slicedList.map(item => item);
              that.setData({
                articleList:resp.data.data.list,
                imageList:tabularCharts
              })
              //console.log(that.data.articleList);
            }
        })
    },

    clickImg:function(e){
        const id=e.currentTarget.dataset.id;
        wx.navigateTo({
          url: '/pages/index/detail/detail?id='+id,
        })
    },

    searchbar(){
      wx.navigateTo({
        url: '/pages/index/searchbar/searchbar',
      })
    },
    assessment(){
      wx.navigateTo({
        url: '/pages/index/assessment/assessment',
      })
    },
    appointment(){
      wx.navigateTo({
        url: '/pages/index/appointment/appointment',
      })
    },
    answerqus(){
        wx.navigateTo({
          url: '/pages/index/ask/answerqus/answerqus',
        })
    },
    psychology(){
      wx.navigateTo({
        url: '/pages/index/psychology/psychology',
      })
    },
    FM(){
      wx.navigateTo({
        url: '/pages/index/FM/FM',
      })
    },
    pwcenter(){
      wx.navigateTo({
        url: '/pages/index/pwcenter/pwcenter',
      })
    },
    toask(){
        if(app.globalData.loginNum==0){
            wx.showModal({
                title: '没有登录',
                content: '是否登录？',
                success: function (res) {
                if (res.confirm) {
                  //跳转到登录页面
                  wx.navigateTo({
                    url: '/pages/mine/login/login',
                  })
                } else {
                console.log('用户点击取消');
                    }
                }
                });
        return;
        }        
        let that = this
        let id = app.globalData.userInfor.id;
        wx.navigateTo({
          url: '/pages/index/ask/ask?id='+id,
        })
    },
    lookmore(){
      wx.navigateTo({
        url: '/pages/index/lookmore/lookmore',
      })
  },
  
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
  
    },
  
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
  
    },
  
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {
  
    },
  
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {
  
    },
  
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
  
    },
  
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
  
    },
  
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
  
    }
  })
